<template>
  <div class="edit-container">
    <el-form v-loading="formLoading" ref="form" :model="form" :rules="rules" label-width="100px">
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-form-item label="益联券" prop="voucherAmount">
          <el-input type="number" v-model="form.voucherAmount" placeholder="益联券金额" maxlength="6" class="col"></el-input>
        </el-form-item>
        <el-form-item label="抵用金" prop="voucherAmount">
          <el-input type="number" v-model="form.deductionAmount" placeholder="益联券金额" maxlength="6" class="col"></el-input>
        </el-form-item>
        <el-form-item label="积分" prop="integral">
          <el-input type="number" v-model="form.integral" placeholder="积分数值" maxlength="6" class="col"></el-input>
        </el-form-item>
      </el-tabs>
      <el-form-item>
        <el-button v-loading="saveLoading" element-loading-background="rgba(0, 0, 0, 0.3)" type="primary"
                   @click="handlerSubmit" v-has-permi="['admin:user:userGrant:save']">保存
        </el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {grant} from "@/api/user";

export default {
  props: {
    id: {
      default: null
    }
  },
  data() {
    return {
      activeName: "first",
      otherInfoVisible: false,
      form: {
        id: null,
        voucherAmount: 0,
        deductionAmount: 0,
        integral: 0,
      },
      rules: {

      },
      roles: [],
      saveLoading: false,
      formLoading: false,
      expressCompanyList:[]
    }
  },
  mounted() {
  },
  methods: {
    handleChange(value) {
    },
    handleClick(tab) {
      if (tab.name === 'second') {
        this.otherInfoVisible = true;
      } else {
        this.otherInfoVisible = false;
      }
    },
    handlerSubmit() {
      if (this.saveLoading || this.formLoading) {
        return;
      }
      this.$refs.form.validate(valid => {
        if (!valid) return;
        this.saveLoading = true;
        this.form.status = 2;
        grant(this.id,this.form.voucherAmount,this.form.integral,this.form.deductionAmount).then(() => {
          this.$message.success('保存成功');
          this.close();
        }).finally(() => {
          this.saveLoading = false
        })
      })
    },
    close() {
      this.$emit('hideGrantDialog')
    }
  }
}
</script>
<style lang="scss" scoped>
.col {
  width: 360px;
}

.img {
  width: 120px;
  height: 120px;
  margin-right: 10px;
}

.imgList {
  display: flex;
  flex-wrap: wrap;

  .img {
    width: 120px;
    height: 120px;
    margin-right: 10px;
  }
}
</style>
